package com.limf.demo.java8;

import java.util.function.Supplier;

public class SupplierTest {

	public static void main(String[] args) {
		//testHelloWorld();  // 测试字符串
		maxNumberTest();   // 测试最大数
		
		Supplier<Person> personSupplier = Person::new;
		personSupplier.get();
	}
	
	static void testHelloWorld() {
		String msgA = "Hello ";
		String msgB = "world ";
		System.out.println(getString(()->msgA+msgB));
		
	}
	private static String getString(Supplier<String> stringSupplier) {
		return stringSupplier.get();
	}
	
	
	static void maxNumberTest() {
		int[] numbers = {100, 200, 300, 400, 500, -600, -700, -800, -900, -1000};
		int numberMax = arrayMax(()->{
			int max = numbers[0];
			for(int number : numbers) {
				if(max < number) {
					max = number;
				}
			}
			return max;
		});
		System.out.println(numberMax);
	}
	
	/**
	 * 获取一个泛型参数指定类型的对象数据
	 * @param integerSupplier 方法的参数为Supplier, 泛型使用Integer
	 * @return 指定类型的对象数据
	 */
	public static Integer arrayMax(Supplier<Integer> integerSupplier) {
		return integerSupplier.get();
	}
}
